import time

from tools import build_vision_msg, create_chat_completion

if __name__ == '__main__':
    queryList = []

    start = time.time()
    with open("query.txt",mode='r',encoding="utf-8") as f:
        queryList = eval(f.read())

    for item in queryList:

        if item['related_image'] is None or item['related_image'] == '':
            continue
        question = item['question']
        img_url = './image/image/'+item['related_image']
        message = build_vision_msg(question, img_url)
        answer = create_chat_completion(message, temperature=0.8, max_tokens=4096, top_p=0.8, use_stream=False)

        record = {
            'question': question,
            'related_image': item['related_image'],
            'answer': answer
        }

        with open('output.txt',mode='a',encoding='utf-8') as h:
            h.write(str(record)+'\n')
        # break
    end = time.time()

    print("耗时：",end-start)